package com.py.credit.service.impl;

import com.py.credit.dao.UploadPublicDao;
import com.py.credit.entity.*;
import com.py.credit.service.UploadPublicService;
import com.py.credit.service.impl.UploadXycnServiceImpl.miTM;
import com.py.credit.utils.SubmitConvXmlUtils;
import com.py.credit.utils.DateUtil;
import com.py.credit.utils.DateUtils;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.cxf.configuration.jsse.TLSClientParameters;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.service.model.BindingInfo;
import org.apache.cxf.service.model.BindingOperationInfo;
import org.apache.cxf.transport.http.HTTPConduit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
import javax.xml.namespace.QName;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;

@Service
public class UploadPublicServiceImpl implements UploadPublicService {
    private final Logger log = LoggerFactory.getLogger(UploadPublicServiceImpl.class);
    protected String apiKey = "B9A7C23C0E394E86B90436740A491958";

    @Autowired
    private UploadPublicDao uploadPublicDao;

    /**
     *
     * @param type
     * @param namespace
     * @param uploadPostUrl
     * @param method
     * @return
     */
    @Override
    public Object uploadJdjc(int type, String namespace, String uploadPostUrl, String method) {
        try {
            String tableName="";
            if(type==0){
                tableName="t_1000000010252_akk9bUnaL3";
                List<SupervisoryReview> list = uploadPublicDao.getSupervisoryReviewByFr(tableName);
                List<List<SupervisoryReview>> parList = ListUtils.partition(list, 999);

                for (int i = 0; i < parList.size(); i++) {
                    List<SupervisoryReview> spList = parList.get(i);
                    PublishSubmitReqData req = new PublishSubmitReqData();
                    req.setXzjc(spList);
                    String xzjcXmlValue = SubmitConvXmlUtils.convert2Xml(req);
                    System.out.println("监督检查转XML内容：{}"+xzjcXmlValue);
                    log.debug("监督检查转XML内容：{}", xzjcXmlValue);
                    String respXzjcValue = doPostSoap1_1(uploadPostUrl, xzjcXmlValue,apiKey, method);
                    log.info("返回监督检查上报结果信息：{}", respXzjcValue);
                    SubmitXzxkRespData xzjcResp = (SubmitXzxkRespData) SubmitConvXmlUtils
                            .convertXml2Object(SubmitXzxkRespData.class, respXzjcValue);
                    //保存返回数据
                
                    List<String> recordIds = spList.stream().map(SupervisoryReview -> SupervisoryReview.getRecordId()).collect(Collectors.toList());
                    this.saveSubmitLogs(type, xzjcResp.getResp(), recordIds, tableName);
                    return respXzjcValue;
                }
             
            }else{
                tableName="t_1000010010430_E0pP6YlewE";
                List<SupervisoryReview> list = uploadPublicDao.getSupervisoryReviewByZrr(tableName);
                List<List<SupervisoryReview>> parList = ListUtils.partition(list, 999);
           
                for (int i = 0; i < parList.size(); i++) {
                    List<SupervisoryReview> spList = parList.get(i);
                    PublishSubmitReqData req = new PublishSubmitReqData();
                    req.setXzjc(spList);
                    String xzjcXmlValue = SubmitConvXmlUtils.convert2Xml(req);
                    System.out.println("监督检查转XML内容：{}"+xzjcXmlValue);
                    log.debug("监督检查转XML内容：{}", xzjcXmlValue);
                    String respXzjcValue = doPostSoap1_1(uploadPostUrl, xzjcXmlValue,apiKey, method);
                    log.info("返回监督检查上报结果信息：{}", respXzjcValue);
                    SubmitXzxkRespData xzjcResp = (SubmitXzxkRespData) SubmitConvXmlUtils
                            .convertXml2Object(SubmitXzxkRespData.class, respXzjcValue);
                    //保存返回数据
                
                    List<String> recordIds = spList.stream().map(SupervisoryReview -> SupervisoryReview.getRecordId()).collect(Collectors.toList());
                    this.saveSubmitLogs(type, xzjcResp.getResp(), recordIds, tableName);
                    return respXzjcValue;
                }
            }	
        } catch (Exception e) {
            e.printStackTrace();
            log.info("上传数据失败:", e.getMessage());
        }
        return null;
    }

    @Override
    public Object uploadXzqz(int type, String namespace, String uploadPostUrl, String method) {
        try {
            String tableName="";
            if(type==0){
                tableName="t_1000000010019_bgWiiN00cb";
                List<XzqzEntity> list = uploadPublicDao.getXzqzByFr(tableName);
                List<List<XzqzEntity>> parList = ListUtils.partition(list, 999);
                
                for (int i = 0; i < parList.size(); i++) {
                    List<XzqzEntity> spList = parList.get(i);
                    PublishSubmitReqData req = new PublishSubmitReqData();
                    req.setXzqz(spList);
                    String xzqzXmlValue = SubmitConvXmlUtils.convert2Xml(req);
                    System.out.println("行政强制转XML内容：{}"+xzqzXmlValue);
                    log.debug("行政强制转XML内容：{}", xzqzXmlValue);
                    String respXzqzValue = doPostSoap1_1(uploadPostUrl, xzqzXmlValue,apiKey, method);
                    log.info("返回行政强制上报结果信息：{}", xzqzXmlValue);
                    SubmitXzxkRespData xzqzResp = (SubmitXzxkRespData) SubmitConvXmlUtils
                            .convertXml2Object(SubmitXzxkRespData.class, respXzqzValue);
                    //保存返回数据
                    
                    List<String> recordIds = spList.stream().map(XzqzEntity -> XzqzEntity.getRecordId()).collect(Collectors.toList());
                    this.saveSubmitLogs(type, xzqzResp.getResp(), recordIds, tableName);
                    return respXzqzValue;
                }
            }else{
                tableName="t_1000010010085_nbWY1hOWBB";
                List<XzqzEntity> list = uploadPublicDao.getXzqzByZrr(tableName);
                List<List<XzqzEntity>> parList = ListUtils.partition(list, 999);
                
                for (int i = 0; i < parList.size(); i++) {
                    List<XzqzEntity> spList = parList.get(i);
                    PublishSubmitReqData req = new PublishSubmitReqData();
                    req.setXzqz(spList);
                    String xzqzXmlValue = SubmitConvXmlUtils.convert2Xml(req);
                    System.out.println("行政强制转XML内容：{}"+xzqzXmlValue);
                    log.debug("行政强制转XML内容：{}", xzqzXmlValue);
                    String respXzqzValue = doPostSoap1_1(uploadPostUrl, xzqzXmlValue,apiKey, method);
                    log.info("返回行政强制上报结果信息：{}", xzqzXmlValue);
                    SubmitXzxkRespData xzqzResp = (SubmitXzxkRespData) SubmitConvXmlUtils
                            .convertXml2Object(SubmitXzxkRespData.class, respXzqzValue);
                    //保存返回数据
                    
                    List<String> recordIds = spList.stream().map(XzqzEntity -> XzqzEntity.getRecordId()).collect(Collectors.toList());
                    this.saveSubmitLogs(type, xzqzResp.getResp(), recordIds, tableName);
                    return respXzqzValue;
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            log.info("上传数据失败:", e.getMessage());
        }
        return null;
    }

    @Override
    public Object uploadXzzs(int type, String namespace, String uploadPostUrl, String method) {
        try {
            String tableName="";
            if(type==0){
                tableName="t_1000000010045_6HelrLv0OJ";
                List<XzzsEntity> list = uploadPublicDao.getXzzsFr(tableName);
                List<List<XzzsEntity>> parList = ListUtils.partition(list, 999);    
                for (int i = 0; i < parList.size(); i++) {
                    List<XzzsEntity> spList = parList.get(i);
                    PublishSubmitReqData req = new PublishSubmitReqData();
                    req.setXzzs(spList);
                    String xzzsXmlValue = SubmitConvXmlUtils.convert2Xml(req);
                    System.out.println("行政征收转XML内容：{}"+xzzsXmlValue);
                    log.debug("行政征收转XML内容：{}", xzzsXmlValue);
                    String respXzzsValue = doPostSoap1_1(uploadPostUrl, xzzsXmlValue,apiKey, method);
                    log.info("返回行政征收上报结果信息：{}", respXzzsValue);
                    SubmitXzxkRespData xzzsResp = (SubmitXzxkRespData) SubmitConvXmlUtils
                            .convertXml2Object(SubmitXzxkRespData.class, respXzzsValue);
                    //保存返回数据
                    
                    List<String> recordIds = spList.stream().map(XzzsEntity -> XzzsEntity.getRecordId()).collect(Collectors.toList());
                    this.saveSubmitLogs(type, xzzsResp.getResp(), recordIds, tableName);
                    return respXzzsValue;
                }
                   
            }else{
                tableName="t_1000010010089_NKoHe65W3V";
                List<XzzsEntity> list = uploadPublicDao.getXzzsByZrr(tableName);
                List<List<XzzsEntity>> parList = ListUtils.partition(list, 999);
                for (int i = 0; i < parList.size(); i++) {
                    List<XzzsEntity> spList = parList.get(i);
                    PublishSubmitReqData req = new PublishSubmitReqData();
                    req.setXzzs(spList);
                    String xzzsXmlValue = SubmitConvXmlUtils.convert2Xml(req);
                    System.out.println("行政征收转XML内容：{}"+xzzsXmlValue);
                    log.debug("行政征收转XML内容：{}", xzzsXmlValue);
                    String respXzzsValue = doPostSoap1_1(uploadPostUrl, xzzsXmlValue,apiKey, method);
                    log.info("返回行政征收上报结果信息：{}", respXzzsValue);
                    SubmitXzxkRespData xzzsResp = (SubmitXzxkRespData) SubmitConvXmlUtils
                            .convertXml2Object(SubmitXzxkRespData.class, respXzzsValue);
                    //保存返回数据
                    
                    List<String> recordIds = spList.stream().map(XzzsEntity -> XzzsEntity.getRecordId()).collect(Collectors.toList());
                    this.saveSubmitLogs(type, xzzsResp.getResp(), recordIds, tableName);
                    return respXzzsValue;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.info("上传数据失败:", e.getMessage());
        }
        return null;
    }

    @Override
    public Object uploadXzjf(int type, String namespace, String uploadPostUrl, String method) {
        try {
            String tableName="";
            if(type==0){
                tableName="t_1000000010081_B1jxBXNyHJ";
                List<XzjfEntity> list = uploadPublicDao.getXzjfByFr(tableName);
                List<List<XzjfEntity>> parList = ListUtils.partition(list, 999);
                for (int i = 0; i < parList.size(); i++) {
                    List<XzjfEntity> spList = parList.get(i);
                    PublishSubmitReqData req = new PublishSubmitReqData();
                    req.setXzjf(spList);
                    String xzjfXmlValue = SubmitConvXmlUtils.convert2Xml(req);
                    System.out.println("行政给付转XML内容：{}"+xzjfXmlValue);
                    log.debug("行政给付转XML内容：{}", xzjfXmlValue);
                    String respXzjfValue = doPostSoap1_1(uploadPostUrl, xzjfXmlValue,apiKey, method);
                    log.info("返回给付征收上报结果信息：{}", respXzjfValue);
                    SubmitXzxkRespData xzjfResp = (SubmitXzxkRespData) SubmitConvXmlUtils
                            .convertXml2Object(SubmitXzxkRespData.class, respXzjfValue);
                    //保存返回数据         
                    List<String> recordIds = spList.stream().map(XzjfEntity -> XzjfEntity.getRecordId()).collect(Collectors.toList());
                    this.saveSubmitLogs(type, xzjfResp.getResp(), recordIds, tableName);
                    return respXzjfValue;
                
                }
            }else{
                tableName="t_1000010010092_FnFxdTFOv9";
                List<XzjfEntity> list = uploadPublicDao.getXzjfByZrr(tableName);
                List<List<XzjfEntity>> parList = ListUtils.partition(list, 999);
                for (int i = 0; i < parList.size(); i++) {
                    List<XzjfEntity> spList = parList.get(i);
                    PublishSubmitReqData req = new PublishSubmitReqData();
                    req.setXzjf(spList);
                    String xzjfXmlValue = SubmitConvXmlUtils.convert2Xml(req);
                    System.out.println("行政给付转XML内容：{}"+xzjfXmlValue);
                    log.debug("行政给付转XML内容：{}", xzjfXmlValue);
                    String respXzjfValue = doPostSoap1_1(uploadPostUrl, xzjfXmlValue,apiKey, method);
                    log.info("返回给付征收上报结果信息：{}", respXzjfValue);
                    SubmitXzxkRespData xzjfResp = (SubmitXzxkRespData) SubmitConvXmlUtils
                            .convertXml2Object(SubmitXzxkRespData.class, respXzjfValue);
                    //保存返回数据         
                    List<String> recordIds = spList.stream().map(XzjfEntity -> XzjfEntity.getRecordId()).collect(Collectors.toList());
                    this.saveSubmitLogs(type, xzjfResp.getResp(), recordIds, tableName);
                    return respXzjfValue;
                
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            log.info("上传数据失败:", e.getMessage());
        }
        return null;
    }

    @Override
    public Object uploadXzjl(int type, String namespace, String uploadPostUrl, String method) {
        try {
            String tableName="";
            if(type==0){
                tableName="t_1000000010082_LuLlDPXj9d";
                List<XzjlEntity> list = uploadPublicDao.getXzjlByFr(tableName);
                List<List<XzjlEntity>> parList = ListUtils.partition(list, 999);
                for (int i = 0; i < parList.size(); i++) {
                    List<XzjlEntity> spList = parList.get(i);
                    PublishSubmitReqData req = new PublishSubmitReqData();
                    req.setXzjl(spList);
                    String xzjlXmlValue = SubmitConvXmlUtils.convert2Xml(req);
                    System.out.println("行政激励转XML内容：{}"+xzjlXmlValue);
                    log.debug("行政激励转XML内容：{}", xzjlXmlValue);
                    String respXzjlValue = doPostSoap1_1(uploadPostUrl, xzjlXmlValue,apiKey, method);
                    log.info("返回行政激励上报结果信息：{}", respXzjlValue);
                    SubmitXzxkRespData xzjlResp = (SubmitXzxkRespData) SubmitConvXmlUtils
                            .convertXml2Object(SubmitXzxkRespData.class, respXzjlValue);
                  //保存返回数据         
                    List<String> recordIds = spList.stream().map(XzjlEntity -> XzjlEntity.getRecordId()).collect(Collectors.toList());
                    this.saveSubmitLogs(type, xzjlResp.getResp(), recordIds, tableName);
                    return respXzjlValue;
                }
            }else{
                tableName="t_1000010010098_ek9kcfC7gn";
                List<XzjlEntity> list = uploadPublicDao.getXzjlByZrr(tableName);
                List<List<XzjlEntity>> parList = ListUtils.partition(list, 999);
                for (int i = 0; i < parList.size(); i++) {
                    List<XzjlEntity> spList = parList.get(i);
                    PublishSubmitReqData req = new PublishSubmitReqData();
                    req.setXzjl(spList);
                    String xzjlXmlValue = SubmitConvXmlUtils.convert2Xml(req);
                    System.out.println("行政激励转XML内容：{}"+xzjlXmlValue);
                    log.debug("行政激励转XML内容：{}", xzjlXmlValue);
                    String respXzjlValue = doPostSoap1_1(uploadPostUrl, xzjlXmlValue,apiKey, method);
                    log.info("返回行政激励上报结果信息：{}", respXzjlValue);
                    SubmitXzxkRespData xzjlResp = (SubmitXzxkRespData) SubmitConvXmlUtils
                            .convertXml2Object(SubmitXzxkRespData.class, respXzjlValue);
                  //保存返回数据         
                    List<String> recordIds = spList.stream().map(XzjlEntity -> XzjlEntity.getRecordId()).collect(Collectors.toList());
                    this.saveSubmitLogs(type, xzjlResp.getResp(), recordIds, tableName);
                    return respXzjlValue;
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            log.info("上传数据失败:", e.getMessage());
        }
        return null;
    }

    @Override
    public Object uploadXzcj(int type, String namespace, String uploadPostUrl, String method) {
        try {
            String tableName="";
            if(type==0){
                tableName="t_1000000010078_72Blr6pCCj";
                List<XzcjEntity> list = uploadPublicDao.getXzcjByFr(tableName);
                List<List<XzcjEntity>> parList = ListUtils.partition(list, 999);
                for (int i = 0; i < parList.size(); i++) {
                    List<XzcjEntity> spList = parList.get(i);
                    PublishSubmitReqData req = new PublishSubmitReqData();
                    req.setXzcj(spList);
                    String xzcjXmlValue = SubmitConvXmlUtils.convert2Xml(req);
                    System.out.println("行政惩戒转XML内容：{}"+xzcjXmlValue);
                    log.debug("行政惩戒转XML内容：{}", xzcjXmlValue);
                    String respXzcjValue = doPostSoap1_1(uploadPostUrl, xzcjXmlValue,apiKey, method);
                    log.info("返回行政惩戒上报结果信息：{}", respXzcjValue);
                    SubmitXzxkRespData xzcjResp = (SubmitXzxkRespData) SubmitConvXmlUtils
                            .convertXml2Object(SubmitXzxkRespData.class, respXzcjValue);
                  //保存返回数据         
                    List<String> recordIds = spList.stream().map(XzcjEntity -> XzcjEntity.getRecordId()).collect(Collectors.toList());
                    this.saveSubmitLogs(type, xzcjResp.getResp(), recordIds, tableName);
                    return respXzcjValue;
                }
            }else{
                tableName="t_1000010010088_bmuDHF0DxX";
                List<XzcjEntity> list = uploadPublicDao.getXzcjByZrr(tableName);
                List<List<XzcjEntity>> parList = ListUtils.partition(list, 999);
                for (int i = 0; i < parList.size(); i++) {
                    List<XzcjEntity> spList = parList.get(i);
                    PublishSubmitReqData req = new PublishSubmitReqData();
                    req.setXzcj(spList);
                    String xzcjXmlValue = SubmitConvXmlUtils.convert2Xml(req);
                    System.out.println("行政惩戒转XML内容：{}"+xzcjXmlValue);
                    log.debug("行政惩戒转XML内容：{}", xzcjXmlValue);
                    String respXzcjValue = doPostSoap1_1(uploadPostUrl, xzcjXmlValue,apiKey, method);
                    log.info("返回行政惩戒上报结果信息：{}", respXzcjValue);
                    SubmitXzxkRespData xzcjResp = (SubmitXzxkRespData) SubmitConvXmlUtils
                            .convertXml2Object(SubmitXzxkRespData.class, respXzcjValue);
                  //保存返回数据         
                    List<String> recordIds = spList.stream().map(XzcjEntity -> XzcjEntity.getRecordId()).collect(Collectors.toList());
                    this.saveSubmitLogs(type, xzcjResp.getResp(), recordIds, tableName);
                    return respXzcjValue;
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            log.info("上传数据失败:", e.getMessage());
        }
        return null;
    }

    @Override
    public Object uploadXzqr(int type, String namespace, String uploadPostUrl, String method) {
        try {
            String tableName="";
            if(type==0){
                tableName="t_1000000010079_fel4Oc0gfQ";
                List<XzqrEntity> list = uploadPublicDao.getXzqrByFr(tableName);
                List<List<XzqrEntity>> parList = ListUtils.partition(list, 999);
                for (int i = 0; i < parList.size(); i++) {
                    List<XzqrEntity> spList = parList.get(i);
                    PublishSubmitReqData req = new PublishSubmitReqData();
                    req.setXzqr(spList);
                    String xzqrXmlValue = SubmitConvXmlUtils.convert2Xml(req);
                    System.out.println("行政确认转XML内容：{}"+xzqrXmlValue);
                    log.debug("行政确认转XML内容：{}", xzqrXmlValue);
                    String respXzqzValue = doPostSoap1_1(uploadPostUrl, xzqrXmlValue,apiKey, method);
                    log.info("返回行政确认上报结果信息：{}", respXzqzValue);
                    SubmitXzxkRespData xzqzResp = (SubmitXzxkRespData) SubmitConvXmlUtils
                            .convertXml2Object(SubmitXzxkRespData.class, respXzqzValue);
                    //保存返回数据         
                    List<String> recordIds = spList.stream().map(XzqrEntity -> XzqrEntity.getRecordId()).collect(Collectors.toList());
                    this.saveSubmitLogs(type, xzqzResp.getResp(), recordIds, tableName);
                    return respXzqzValue;
                }
            }else{
                tableName="t_1000010010091_HoTa38mRD1";
                List<XzqrEntity> list = uploadPublicDao.getXzqrByZrr(tableName);
                List<List<XzqrEntity>> parList = ListUtils.partition(list, 999);
                for (int i = 0; i < parList.size(); i++) {
                    List<XzqrEntity> spList = parList.get(i);
                    PublishSubmitReqData req = new PublishSubmitReqData();
                    req.setXzqr(spList);
                    String xzqrXmlValue = SubmitConvXmlUtils.convert2Xml(req);
                    System.out.println("行政确认转XML内容：{}"+xzqrXmlValue);
                    log.debug("行政确认转XML内容：{}", xzqrXmlValue);
                    String respXzqzValue = doPostSoap1_1(uploadPostUrl, xzqrXmlValue,apiKey, method);
                    log.info("返回行政确认上报结果信息：{}", respXzqzValue);
                    SubmitXzxkRespData xzqzResp = (SubmitXzxkRespData) SubmitConvXmlUtils
                            .convertXml2Object(SubmitXzxkRespData.class, respXzqzValue);
                    //保存返回数据         
                    List<String> recordIds = spList.stream().map(XzqrEntity -> XzqrEntity.getRecordId()).collect(Collectors.toList());
                    this.saveSubmitLogs(type, xzqzResp.getResp(), recordIds, tableName);
                    return respXzqzValue;
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            log.info("上传数据失败:", e.getMessage());
        }
        return null;
    }

    @Override
    public Object uploadQtxzgl(int type, String namespace, String uploadPostUrl, String method) {
        try {
            String tableName="";
            if(type==0){
                tableName="t_1000000010083_bisEXzGGeF";
                List<XzqtglEntity> list = uploadPublicDao.getXzqtByFr(tableName);
                List<List<XzqtglEntity>> parList = ListUtils.partition(list, 999);
                for (int i = 0; i < parList.size(); i++) {
                    List<XzqtglEntity> spList = parList.get(i);
                    PublishSubmitReqData req = new PublishSubmitReqData();
                    req.setXzqtgl(spList);
                    String xzqtglXmlValue = SubmitConvXmlUtils.convert2Xml(req);
                    System.out.println("行政其他转XML内容：{}"+xzqtglXmlValue);
                    log.debug("行政其他转XML内容：{}", xzqtglXmlValue);
                    String respXzjcValue = doPostSoap1_1(uploadPostUrl, xzqtglXmlValue,apiKey, method);
                    log.info("返回行政其他上报结果信息：{}", respXzjcValue);
                    SubmitXzxkRespData xzxkResp = (SubmitXzxkRespData) SubmitConvXmlUtils
                            .convertXml2Object(SubmitXzxkRespData.class, respXzjcValue);
                    //保存返回数据         
                    List<String> recordIds = spList.stream().map(XzqtglEntity -> XzqtglEntity.getRecordId()).collect(Collectors.toList());
                    this.saveSubmitLogs(type, xzxkResp.getResp(), recordIds, tableName);
                    return respXzjcValue;
                }
            }else{
                tableName="t_1000010010100_4bjNpPRKrv";
                List<XzqtglEntity> list = uploadPublicDao.getXzqtByZrr(tableName);
                List<List<XzqtglEntity>> parList = ListUtils.partition(list, 999);
                for (int i = 0; i < parList.size(); i++) {
                    List<XzqtglEntity> spList = parList.get(i);
                    PublishSubmitReqData req = new PublishSubmitReqData();
                    req.setXzqtgl(spList);
                    String xzqtglXmlValue = SubmitConvXmlUtils.convert2Xml(req);
                    System.out.println("行政其他转XML内容：{}"+xzqtglXmlValue);
                    log.debug("行政其他转XML内容：{}", xzqtglXmlValue);
                    String respXzjcValue = doPostSoap1_1(uploadPostUrl, xzqtglXmlValue,apiKey, method);
                    log.info("返回行政其他上报结果信息：{}", respXzjcValue);
                    SubmitXzxkRespData xzxkResp = (SubmitXzxkRespData) SubmitConvXmlUtils
                            .convertXml2Object(SubmitXzxkRespData.class, respXzjcValue);
                    //保存返回数据         
                    List<String> recordIds = spList.stream().map(XzqtglEntity -> XzqtglEntity.getRecordId()).collect(Collectors.toList());
                    this.saveSubmitLogs(type, xzxkResp.getResp(), recordIds, tableName);
                    return respXzjcValue;
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            log.info("上传数据失败:", e.getMessage());
        }
        return null;
    }

    /**
     * 使用SOAP1.1发送消息
     *
     * @param postUrl
     * @param soapXml
     * @param soapAction
     * @return
     */
    public String doPostSoap1_1(String postUrl, String soapXml, String apiKey,
                                String soapAction) throws UnsupportedEncodingException {
    	javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(

   			new javax.net.ssl.HostnameVerifier(){

    			public boolean verify(String hostname,

    			javax.net.ssl.SSLSession sslSession) {
    			return true;


    			}

    			});

    			System.clearProperty("javax.net.ssl.trustStore");

    			System.clearProperty("javax.net.ssl.trustStorePassword");

    			try {

    			//这里需要注意的是证书路径如果有空格，上面getPath()会把空格转码为%20F，需要转一次码，其他特殊字符也需注意
    		    	  System.setProperty("javax.net.ssl.trustStore", "C:\\cacerts");
    		    	  System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
    		    	  System.setProperty("org.jboss.security.ignoreHttpsHost", "true");
    			} catch (Exception e) {

    			e.printStackTrace();

    			}
    	try {
			trustAllHttpsCertificates();
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
    	HttpsURLConnection.setDefaultHostnameVerifier(hv);
    	
        try {
            Properties props = System.getProperties();
            props.setProperty("org.apache.cxf.stax.allowInsecureParser", "1");
            props.setProperty("UseSunHttpHandler", "true");
            props.setProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");;
            String nameSpace = "http://dal.rjcloud.dal";
            TLSClientParameters tlsParams = new TLSClientParameters();
			tlsParams.setDisableCNCheck(true);
			
            JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
            Client client = clientFactory.createClient(postUrl);
            HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
			httpConduit.setTlsClientParameters(tlsParams);
            System.out.println("请求地址:"+postUrl);
            System.out.println("请求方法:"+soapAction);
            Object[] obj = client.invoke(soapAction, new Object[]{apiKey,soapXml});
            System.out.println("请求结果:");
            System.out.println(String.valueOf(obj[0]));
            return String.valueOf(obj[0]);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
    return "";
    }


    public  String getImgStrBase64(String imagePath) {
        // 将图片文件转化为字节数组字符串，并对其进行Base64编码处理
        if(StringUtils.isNotBlank(imagePath)){
            InputStream in = null;
            byte[] data = null;
            // 读取图片字节数组
            try {
                in = new FileInputStream(imagePath);
                data = new byte[in.available()];
                in.read(data);
                in.close();
            } catch ( Exception e) {
                e.printStackTrace();
            }
            return Base64.encodeBase64String(data);
        }
        return "";

    }

    /**
     *
     * @param promiseList
     * @return
     */
    public List<FrPromiseBookBean> convert264(List<FrPromiseBookBean> promiseList){
        for (FrPromiseBookBean promise:promiseList){
            promise.setPath_byte64(getImgStrBase64(promise.getPath_byte64()));
        }
        return promiseList;
    }
    /**
     *
     * @param promiseList
     * @return
     */
    public List<ZrrPromiseBookBean> convertZRR264(List<ZrrPromiseBookBean> promiseList){
        for (ZrrPromiseBookBean promise:promiseList){
            promise.setPath_byte64(getImgStrBase64(promise.getPath_byte64()));
        }
        return promiseList;
    }
    public static Object[] invokeRemoteMethod(String url, String operation, Object[] parameters){
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        if (!url.endsWith("wsdl")) {
            url += "?wsdl";
        }
        org.apache.cxf.endpoint.Client client = dcf.createClient(url);
        //处理webService接口和实现类namespace不同的情况，CXF动态客户端在处理此问题时，会报No operation was found with the name的异常
        Endpoint endpoint = client.getEndpoint();
        QName opName = new QName(endpoint.getService().getName().getNamespaceURI(),operation);
        BindingInfo bindingInfo= endpoint.getEndpointInfo().getBinding();
        if(bindingInfo.getOperation(opName) == null){
            for(BindingOperationInfo operationInfo : bindingInfo.getOperations()){
                if(operation.equals(operationInfo.getName().getLocalPart())){
                    opName = operationInfo.getName();
                    break;
                }
            }
        }
        Object[] res = null;
        try {
            res = client.invoke(opName, parameters);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return res;
    }

    /**
     *
     * @param type type
     * @param respList 返回值
//     * @param xzxkList 许可集合
//     * @param xzcfList 处罚集合
     * @param tableName 表名
     */
    @Transactional
     void saveSubmitLogs(int type, List<SubmitRespBean> respList, List<String> recordIds,String tableName) {
        // 保存上报记录信息及明细信息
        DateUtil dataUtil = DateUtil.getInstance();
        String batNo = "BN" + dataUtil.getCurrDate(DateUtil.YYYYMMDDHHMMSS);
        String subDate = dataUtil.getCurrDate(DateUtil.YYYY_MM_DD);
        SubmitLogsInfo logsInfo = new SubmitLogsInfo();

        int respSize = respList.size();
        SubmitLogsDetails detail = null;
        ArrayList<SubmitLogsDetails> detList = new ArrayList<SubmitLogsDetails>();
        //原数据的recordIds 集合
     
   
          
            for (int i = 0; i < respSize; i++) {
                SubmitRespBean reps = respList.get(i);
                if (reps != null && reps.getLine() != null) {
           
                    detail = new SubmitLogsDetails();
                    detail.setBatNo(batNo);
                    detail.setSubCode(reps.getCode());
                    detail.setSubMsg(reps.getMsg());
                    detail.setRelId(recordIds.get(Integer.valueOf(reps.getLine())));
        
                    detail.setRecStatus("1");
                    detList.add(detail);
                } else {
                    logsInfo.setRemarkInfo(reps.getCode() + ":" + reps.getMsg());
                }
            }
 
        //
        ArrayList<SubmitRespBean> sucList = (ArrayList<SubmitRespBean>) respList.stream()
                .filter((SubmitRespBean resp) -> "00".equals(resp.getCode())).collect(Collectors.toList());

//        uploadPublicDao.updateXzStatusByRecordIds(tableName,recordIds);//需改原数据的状态
        int sucSize = sucList.size();// 成功条数

        logsInfo.setBatNo(batNo);
        logsInfo.setType(type);
        logsInfo.setSubDate(subDate);
        logsInfo.setSuccNum("" + sucSize);
        logsInfo.setFailNum("" + (respList.size() - sucSize));
        logsInfo.setRecStatus("1");
        uploadPublicDao.saveSubmitLogsInfo(logsInfo);
        // 保存上报数据明细
        if (null == logsInfo.getRemarkInfo() || "".equals(logsInfo.getRemarkInfo())) {
        	uploadPublicDao.saveSubmitLogsDetails(detList);
        }
    }
    
    HostnameVerifier hv = new HostnameVerifier() {
        public boolean verify(String urlHostName, SSLSession session) {
            System.out.println("Warning: URL Host: " + urlHostName + " vs. "
                               + session.getPeerHost());
            return true;
        }
    };

 	private static void trustAllHttpsCertificates() throws Exception {
 		javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1];
 		javax.net.ssl.TrustManager tm = new miTM();
 		trustAllCerts[0] = tm;
 		javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext
 				.getInstance("SSL");
 		sc.init(null, trustAllCerts, null);
 		javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc
 				.getSocketFactory());
 	}

 	static class miTM implements javax.net.ssl.TrustManager,
 			javax.net.ssl.X509TrustManager {
 		public java.security.cert.X509Certificate[] getAcceptedIssuers() {
 			return null;
 		}

 		public boolean isServerTrusted(
 				java.security.cert.X509Certificate[] certs) {
 			return true;
 		}

 		public boolean isClientTrusted(
 				java.security.cert.X509Certificate[] certs) {
 			return true;
 		}

 		public void checkServerTrusted(
 				java.security.cert.X509Certificate[] certs, String authType)
 				throws java.security.cert.CertificateException {
 			return;
 		}

 		public void checkClientTrusted(
 				java.security.cert.X509Certificate[] certs, String authType)
 				throws java.security.cert.CertificateException {
 			return;
 		}
 	}
}
